﻿using BoriPeter.FitnessJournal8.Interfaces.DataSources;
using BoriPeter.FitnessJournal8.Models;
using BoriPeter.NutritionFileSource.Models;
using BoriPeter.NutritionFileSource.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.NutritionFileSource
{
    public class AllFoodFileSource : IFoodDataSource
    {
        private string FileName;

        #region Constructor
        public AllFoodFileSource(string _fileName)
        {
            FileName = _fileName;
        }
        #endregion 

        #region GetAllAsync()
        public async Task<List<FitnessJournal8.Models.Food>> GetAllAsync()
        {
            var source = new FileSource<FoodList, FoodItem>(FileName);
            List<FoodItem> list = await source.ReadAllFromFileAsync();
            return list.Convert();
        }
        #endregion

        #region GetById()
        public async Task<FitnessJournal8.Models.Food> GetById(int _id)
        {
            var source = new FileSource<FoodList, FoodItem>(FileName);
            List<FoodItem> list = await source.ReadAllFromFileAsync();
            foreach (var item in list)
            {
                if (item.Id == _id)
                {
                    return item.Convert();
                }
            }
            return null;
        }
        #endregion

        #region SaveAll()
        public Task SaveAll(FitnessJournal8.Models.Food _list)
        {
            throw new NotImplementedException();
        }
        #endregion


        public Task<Food> GetByIdAsync(int _id)
        {
            throw new NotImplementedException();
        }

        public Task<Food> GetWhereAsync(Func<Food, bool> _expression)
        {
            throw new NotImplementedException();
        }

        public Task SaveAllAsync(List<Food> _list)
        {
            throw new NotImplementedException();
        }

        public Task SaveAsync(Food _food)
        {
            throw new NotImplementedException();
        }
    }
}
